<template>
  <el-form
    :model="ruleForm"
    :rules="rules"
    ref="ruleForm"
    label-width="120px"
    size="mini"
  >
    <el-form-item label="商圈名称: " prop="name">
      <el-input v-model="ruleForm.name" style="width:50%;" placeholder="给目标起个名字"></el-input>
    </el-form-item>
    <el-form-item label="商圈位置: " prop="name">
        <div class="flex">
            <el-input v-model="ruleForm.name22" style="width:50%;marginRight:15px;" placeholder="添加商圈位置"></el-input>
            <div style="width:100px;height:100px;border:1px solid red">地图</div>
        </div>
    </el-form-item>

    <el-form-item label="商圈分类" prop="region">
      <el-select v-model="ruleForm.region" placeholder="请选择活动区域">
        <el-option label="区域一" value="shanghai"></el-option>
        <el-option label="区域二" value="beijing"></el-option>
      </el-select>
    </el-form-item>

    <el-form-item label="推荐标签: " prop="name">
        <div class="flex_row">
            <el-input class="margin_r_15" v-model="ruleForm.name" style="flex:1;" placeholder="推荐短语不超过8个字"></el-input>
            <el-input class="margin_r_15" v-model="ruleForm.name" style="flex:1;" placeholder="推荐短语不超过8个字"></el-input>
            <el-input v-model="ruleForm.name" style="flex:1;" placeholder="推荐短语不超过8个字"></el-input>
        </div>
    </el-form-item>

    <el-form-item label="推荐语: " prop="desc">
      <el-input type="textarea" v-model="ruleForm.desc" :autosize="{ minRows: 4, maxRows: 6}"></el-input>
    </el-form-item>

    <el-form-item label="关联商家: " prop="region12">
        <el-input v-model="ruleForm.name" class="margin_b_15" style="width:50%;" placeholder="搜索关联商家"></el-input>
       <el-transfer
            style="text-align: left; display: inline-block"
            v-model="value"
            :left-default-checked="[2, 3]"
            :right-default-checked="[1]"
            :render-content="renderFunc"
            :titles="['关联商家列表', '选中关联商家']"
            :button-texts="['取消关联商家', '添加关联商家']"
            :format="{
                noChecked: '${total}',
                hasChecked: '${checked}/${total}'
            }"
            @change="handleChange"
            :data="data">
        </el-transfer>
    </el-form-item>

    <!-- 上传图片 -->
    <el-form-item prop="img" label="上传图片: ">
        <upload-img></upload-img>

        <div class="colorRed">* 只支持 16:9 的 .jpg, .png 格式</div>
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
      <el-button @click="resetForm('ruleForm')">重置</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import UploadImg from './UploadImg'
export default {
  components: {
    UploadImg
  },
  data () {
    // 假数据
    const generateData = _ => {
      const data = []
      for (let i = 1; i <= 15; i++) {
        data.push({
          key: i,
          label: `备选项 ${i}`,
          disabled: i % 4 === 0
        })
      }
      return data
    }
    return {
      data: generateData(),
      value: [1],
      renderFunc (h, option) {
        return <span>{ option.key } - { option.label }</span>
      },
      // 上面是穿梭框用的数据
      ruleForm: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: '',
        name22: '台江区'
      },
      rules: {
        name: [
          { required: true, message: '请输入活动名称', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ],
        region: [
          { required: true, message: '请选择活动区域', trigger: 'change' }
        ],
        date1: [
          {
            type: 'date',
            required: true,
            message: '请选择日期',
            trigger: 'change'
          }
        ],
        date2: [
          {
            type: 'date',
            required: true,
            message: '请选择时间',
            trigger: 'change'
          }
        ],
        type: [
          {
            type: 'array',
            required: true,
            message: '请至少选择一个活动性质',
            trigger: 'change'
          }
        ],
        resource: [
          { required: true, message: '请选择活动资源', trigger: 'change' }
        ],
        desc: [{ required: true, message: '请填写活动形式', trigger: 'blur' }]
      }
    }
  },
  methods: {
    submitForm (formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          alert('submit!')
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm (formName) {
      this.$refs[formName].resetFields()
    },

    handleChange (value, direction, movedKeys) {
      console.log(value, direction, movedKeys)
    }
  }
}
</script>
